﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Jinjia.Approve.Entity.Entity.JJFlow;
using Jinjia.Approve.Model.VM.JJFlow.DTO;
using Jinjia.Approve.Model.VM.JJFlow.Request;
using Jinjia.Core.BaseInfrastructure.StorageModel.Model;

namespace Jinjia.Approve.IRepository.JJFlow
{
    public interface IFlowInstanceEmpRepository
    {
        Task<List<EmpInfo>> GetInstanceNodeEmp(int node_id, int instance_id, int template_id);

        Task<List<EmpInfo>> GetInstanceNodeEmp(int node_id, int instance_id, int template_id, int is_complete);

        Task<List<EmpInfo>> GetInstanceUserInfo(int instance_id, int template_id);

        Task Save(jj_flow_instance_emp data);
        
        Task Save(List<jj_flow_instance_emp> data);

        Task<bool> CheckNodeUser(int node_id, int template_id, int user_id, int instance_id);

        Task<bool> CheckNodeTrack(int node_id, int user_id, int instance_id);

        /// <summary>
        /// 其他人是否审批通过
        /// </summary>
        /// <param name="user_id"></param>
        /// <param name="node_id"></param>
        /// <param name="instance_id"></param>
        /// <returns></returns>
        Task<bool> IsApprovalCompleted(int user_id, int node_id, int instance_id);

        /// <summary>
        /// 获取过去节点已审批人
        /// </summary>
        /// <param name="instance_id"></param>
        /// <param name="sequence"></param>
        /// <returns></returns>
        Task<List<jj_flow_instance_emp>> GetFormerlyNodeApprover(int instance_id, int sequence);

        /// <summary>
        /// 获取未来节点所有审批人
        /// </summary>
        /// <param name="instance_id"></param>
        /// <param name="sequence"></param>
        /// <returns></returns>
        Task<List<jj_flow_instance_emp>> GetFutureNodeApprover(int instance_id, int sequence);

        /// <summary>
        /// 获取单据的指定节点的审批人信息
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="nodeId"></param>
        /// <returns></returns>
        Task<List<jj_flow_instance_emp>> GetList(int instanceId, int nodeId);

        /// <summary>
        /// 查询待审批的审批人列表
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="instanceIds"></param>
        /// <returns></returns>
        Task<List<InstanceEmpDTO>> GetApprovalPendingList(int userId, List<int> instanceIds, List<int> instanceEmpIds);

        /// <summary>
        /// 审批单据更换审批人
        /// </summary>
        /// <param name="handoverUserId"></param>
        /// <param name="userId"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        Task<bool> ChangeApprover(int handoverUserId, int userId, List<int> ids);

        Task<jj_flow_instance_emp> GetUserInstanceEmp(int user_id, int node_id, int instance_id);
        
        Task<List<jj_flow_instance_emp>> GetInstanceEmpListByUserId(string modular_key, int user_id);

        Task<List<jj_flow_instance_emp>> GetInstanceEmpByBIdAndNId(string biz_order_id, string modular_key);

        Task<List<jj_flow_instance_emp>> GetListByTemplateIdAndInstanceId(int instanceId, int template_id);

        /// <summary>
        /// 获取用户是否有待审核数据权限
        /// </summary>
        /// <param name="system_key"></param>
        /// <param name="big_modular_key"></param>
        /// <param name="modular_key"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        Task<bool> GetUserPower(string system_key, string big_modular_key, string modular_key, int user_id);

        /// <summary>
        /// 待我审核数据
        /// </summary>
        /// <param name="modular_key"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        Task<List<string>> GetUserBizOrderId(string modular_key, int user_id);

        /// <summary>
        /// 首页 待办 汇总（本质是待我审核的单据）
        /// </summary>
        /// <param name="currentUserId"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        Task<PageListSearchResultVM<MyTodoListOverview>> GetTodoListForCurrentUser(int currentUserId, SearchConditionBaseInput input);
        /// <summary>
        /// 首页 待办 汇总的总条数
        /// </summary>
        /// <param name="currentUserId"></param>
        /// <returns></returns>
        Task<int> GetMyTodoListCount(int currentUserId);
        /// <summary>
        /// 首页 待办 详情
        /// </summary>
        /// <param name="currentUserId"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        Task<PageListSearchResultVM<MyTodoListDetail>> GetTodoListDetailForCurrentUser(int currentUserId, GetToDoListDetailByTab input);
        /// <summary>
        /// 通过url检索页面信息
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        Task<IReadOnlyList<SearchByUrlResponse>> SearchByUrl(string url);
        /// <summary>
        /// 审批记录重置
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="nodeIds"></param>
        /// <returns></returns>
        Task<bool> RecordReset(int instanceId, List<int> nodeIds);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="expression">表达式</param>
        /// <returns>处理行数</returns>
        Task<int> DeleteAsync(Expression<Func<jj_flow_instance_emp, bool>> expression);
    }
}